package com.thinkcoder.controller;

import com.thinkcoder.protocol.Result;
import com.thinkcoder.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

@RestController
@RequestMapping("/user")
@Validated
public class UserController {

    private UserService userService;

    @Autowired
    public UserController(UserService userService){
        this.userService=userService;
    }

    @GetMapping("/gettoken")
    public Result<String> getToken(@NotBlank(message = "用户id不能为空") @RequestParam String userId, @NotBlank(message = "用户密码不能为空") @RequestParam String userPwd){
        return Result.buildSuccess(this.userService.getToken(userId,userPwd));
    }

    @GetMapping("/test")
    public Result<String> test(){
        return Result.buildSuccess("成功");
    }
}
